<?php

require_once dirname(__FILE__) . '/../Entry.php';
require_once dirname(__FILE__) . '/../Rams.php';
require_once dirname(__FILE__) . '/Extension/TrafficContent.php';

class Rams_TrafficEntry extends Raws_Entry
{
    protected $_entryClassName = 'Rams_TrafficEntry';

    # entry attributes
    protected $_type = null;
    protected $_kind = null;

    public function __construct($element = null)
    {
        parent::__construct($element);
    }

    public function getDOM($doc = null)
    {
        $element = parent::getDOM($doc);
        // Appending the content element is already done by the base class (= Zend_Gdata_App_Entry) getDOM()
        // BY DOING IT HERE, the content element will be present twice if you call getXML()
        // if ($this->_content != null) {
        //     $element->appendChild($this->_content->getDOM($element->ownerDocument));
        // }
        if ($this->_kind != null) {
            $element->setAttribute('kind', $this->_kind);
        }
        if ($this->_type != null) {
            $element->setAttribute('type', $this->_type);
        }
        return $element;
    }

    protected function takeChildFromDOM($child)
    {
        $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
        switch ($absoluteNodeName) {
        case $this->lookupNamespace('atom') . ':' . 'content':
            $content = new Rams_Extension_TrafficContent();
            $content->transferFromDOM($child);
            $this->_content = $content;
            break;
        default:
            parent::takeChildFromDOM($child);
            break;
        }
    }

    protected function takeAttributeFromDOM($attribute)
    {
        switch ($attribute->localName) {
        case 'kind':
            $this->_kind = $attribute->nodeValue;
            break;
        case 'type':
            $this->_type = $attribute->nodeValue;
            break;
        default:
            parent::takeAttributeFromDOM($attribute);
        }
    }
    
    public function getKind()
    {
        return $this->_kind;
    }

    public function setKind($value)
    {
        $this->_kind = $value;
        return $this;
    }
  
    public function getType()
    {
       return $this->_type;
    }

    public function setType($value)
    {
       $this->_type = $value;
       return $this;
    }
   
}
